class Bill < ActiveRecord::Base

  attr_accessible :customer_id, :electrician_id, :is_cash_bill, :is_new_and_one_time_customer, :on_date, :total_amount,:solds_attributes

  belongs_to :customer, :class_name => "Person"
  belongs_to :electrician, :class_name => "Person"

  has_many :solds
  accepts_nested_attributes_for :solds, :allow_destroy => true

  validates :total_amount, :numericality => {:grater_than => 0}
  validates :electrician_id, :presence => true
  #validates :customer_id, :presence => true

  after_initialize :set_todays_date_as_bill_date

  def set_todays_date_as_bill_date()
    self.on_date ||= Date.today if new_record?
  end

end
